/*
 * Copyright (C) 2017-2021
 * All rights reserved, Designed By 深圳中科鑫智科技有限公司
 * Copyright authorization contact 18814114118
 */
package com.shop.zkmall.admin.controller;

import com.shop.zkmall.admin.annotation.NoRepeatSubmit;
import com.shop.zkmall.admin.param.product.RecommendProductParam;
import com.shop.zkmall.admin.service.product.CereShopProductService;
import com.shop.zkmall.commons.domain.user.CerePlatformUser;
import com.shop.zkmall.commons.result.Result;
import com.shop.zkmall.commons.utils.GsonUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("product")
@Slf4j(topic = "ProductController")
@Tag(name = "商品管理模块", description = "商品管理模块")
public class ProductController {

    @Autowired
    private CereShopProductService cereShopProductService;

    /**
     * 推荐商品数据
     *
     * @param param
     * @return
     */
    @PostMapping(value = "recommendProduct")
    @NoRepeatSubmit
    @Operation(summary = "推荐商品")
    public Result recommendProduct(@RequestBody RecommendProductParam param,
                                   HttpServletRequest request) {
        //获取当前登录账户
        //CerePlatformBusiness user = (CerePlatformBusiness) request.getAttribute("user");
        //param.setShopId(ContextUtil.getShopId());
        CerePlatformUser user = (CerePlatformUser) request.getAttribute("user");
        cereShopProductService.recommendProduct(param, user);
        return new Result(user.getUsername(), "推荐商品", GsonUtil.objectToGson(param));
    }

}
